/*****************************************************************************/
/**
*
* @file led.c
*
* User defined functions about gpios of stm32.
* Target device: STM32F103RET6.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver   Who    Date   	Changes
* ----- ---- ---------- -------------------------------------------------------
* 0.01  abu  01/22/2020 Created
* </pre>
*
*------------------------------------------------------------------------------
* Author:	abu
*					E-mail:	abu_liu@opencores.org
*------------------------------------------------------------------------------
*
******************************************************************************/

/***************************** Include Files *********************************/
#include "bsp_led.h"

/************************** Function Prototypes ******************************/

/*****************************************************************************/
/**
*
* @brief	Initialise all leds.
*
* @param	None.
* @param  None.	
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
void led_init(void)
{
	GPIO_InitTypeDef led;
	
	//open port clock
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
	
	//led yellow
	led.GPIO_Pin = LED_YELLOW_PIN;
	led.GPIO_Speed = GPIO_Speed_50MHz;
	led.GPIO_Mode = GPIO_Mode_Out_PP;
	
	GPIO_Init(LED_YELLOW_PORT, &led);
	LED_YELLOW_OFF();
	
	//led red
	led.GPIO_Pin = LED_RED_PIN;
	led.GPIO_Speed = GPIO_Speed_50MHz;
	led.GPIO_Mode = GPIO_Mode_Out_PP;
	
	GPIO_Init(LED_RED_PORT, &led);
	LED_RED_OFF();

	//led green
	led.GPIO_Pin = LED_GREEN_PIN;
	led.GPIO_Speed = GPIO_Speed_50MHz;
	led.GPIO_Mode = GPIO_Mode_Out_PP;
	
	GPIO_Init(LED_GREEN_PORT, &led);
	LED_GREEN_OFF();
	
	//led blue
	led.GPIO_Pin = LED_BLUE_PIN;
	led.GPIO_Speed = GPIO_Speed_50MHz;
	led.GPIO_Mode = GPIO_Mode_Out_PP;
	
	GPIO_Init(LED_BLUE_PORT, &led);
	LED_BLUE_OFF();

}

/*****************************************************************************/
/**
*
* @brief	Toggle the status of yellow led.
*
*
* @param	None.
* @param  None.	
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
void Led_Yellow_Toggle(void)
{
	uint8_t led_status;
	led_status = GPIO_ReadOutputDataBit(LED_YELLOW_PORT,LED_YELLOW_PIN);
	
	if(led_status == (uint8_t) Bit_SET)
		LED_YELLOW_ON();
	else
		LED_YELLOW_OFF();
}

/*****************************************************************************/
/**
*
* @brief	Toggle the status of red led.
*
*
* @param	None.
* @param  None.	
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
void Led_Red_Toggle(void)
{
	uint8_t led_status;
	led_status = GPIO_ReadOutputDataBit(LED_RED_PORT,LED_RED_PIN);
	
	if(led_status == (uint8_t) Bit_SET)
		LED_RED_ON();
	else
		LED_RED_OFF();
}

/*****************************************************************************/
/**
*
* @brief	Toggle the status of green led.
*
*
* @param	None.
* @param  None.	
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
void Led_Green_Toggle(void)
{
	uint8_t led_status;
	led_status = GPIO_ReadOutputDataBit(LED_GREEN_PORT,LED_GREEN_PIN);
	
	if(led_status == (uint8_t) Bit_SET)
		LED_GREEN_ON();
	else
		LED_GREEN_OFF();
}

/*****************************************************************************/
/**
*
* @brief	Toggle the status of blue led.
*
*
* @param	None.
* @param  None.	
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
void Led_Blue_Toggle(void)
{
	uint8_t led_status;
	led_status = GPIO_ReadOutputDataBit(LED_BLUE_PORT,LED_BLUE_PIN);
	
	if(led_status == (uint8_t) Bit_SET)
		LED_BLUE_ON();
	else
		LED_BLUE_OFF();
}